package top.nana7mi.union_intro_backend.result;

public class RestResult<T> {

    private int code;
    private String msg;
    private T data;


    public RestResult(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public RestResult(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> RestResult<T> success(T data) {
        return new RestResult<>(200, "ok", data);
    }

    public static <T> RestResult<T> success() {
        return new RestResult<>(200, "ok", null);
    }

    public static <T> RestResult<T> success(int code, String msg) {
        return new RestResult<>(code, msg, null);
    }

    public static <T> RestResult<T> success(int code) {
        return new RestResult<>(code, null);
    }

    public static <T> RestResult<T> error(int code) {
        return new RestResult<>(code, "error");
    }

    public static <T> RestResult<T> error(int code, String msg) {
        return new RestResult<>(code, msg);
    }


    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

}
